package com.ohc.leetcode.栈;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

public class 回文数09 {

    public static boolean isPalindrome(int x) {
        if (x < 0) {
            return false;
        }
        List<Integer> list = new ArrayList<>();
        Stack<Integer> stack = new Stack<>();
        while (x > 0) {
            list.add(x % 10);
            stack.push(x % 10);
            x = x / 10;
        }
        int i = 0;
        while (!stack.empty()) {
            if (list.get(i) != stack.pop()) {
                return false;
            }
            i++;
        }
        return true;
    }

    public static void main(String[] args) {
        int num = 1211;
        boolean palindrome = isPalindrome(num);
        System.out.println("palindrome = " + palindrome);
    }
}
